
class ScorePanel {
    score = 0;
    level = 1;

    //设置变量限制等级
    maxLevel:number;

    //设置变量表示多少分升级
    upScore:number;

    scoreElement: HTMLElement;

    levelElement: HTMLElement;

    constructor(maxLevel:number=10,upScore:Number=10) {
        //获取页面中食物元素，非空断言
        this.scoreElement = document.getElementById("score")!;
        this.levelElement = document.getElementById("level")!;
        this.maxLevel=maxLevel;
        this.upScore=maxLevel;
    }

    //加分方法
    addScore() {
        this.scoreElement.innerHTML = ++this.score + "";
        //判断分数
        if(this.score%this.upScore==0){
            this.levelUp();
        }
    }

    // 提升等级方法
    levelUp() {
        if (this.level < this.maxLevel) {
            this.levelElement.innerHTML = ++this.level + "";
        }
    }
}

// 测试代码
// const scorePanel = new ScorePanel();
export default ScorePanel;